package cn.edu.bs.service.impl;

import cn.edu.bs.dao.mapper.TypeMapper;
import cn.edu.bs.domain.Type;
import cn.edu.bs.domain.TypeExample;
import cn.edu.bs.domain.custom.TypeCustom;
import cn.edu.bs.service.TypeService;
import cn.edu.bs.web.request.type.TypeFormCommand;
import cn.edu.bs.web.vo.TypeVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author bs
 */
@Service("typeService")
public class TypeServiceImpl implements TypeService {

    private final TypeMapper typeMapper;

    @Autowired
    public TypeServiceImpl(TypeMapper typeMapper) {
        this.typeMapper = typeMapper;
    }

    @Override
    public long countByExample(TypeExample example) {
        return typeMapper.countByExample(example);
    }

    @Override
    public int deleteByExample(TypeExample example) {
        return typeMapper.deleteByExample(example);
    }

    @Override
    public int deleteByPrimaryKey(Integer id) {
        return typeMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int insert(Type record) {
        return typeMapper.insert(record);
    }

    @Override
    public int insertSelective(Type record) {
        return typeMapper.insertSelective(record);
    }

    @Override
    public List<Type> selectByExample(TypeExample example) {
        return typeMapper.selectByExample(example);
    }

    @Override
    public Type selectByPrimaryKey(Integer id) {
        return typeMapper.selectByPrimaryKey(id);
    }

    @Override
    public int updateByExampleSelective(Type record, TypeExample example) {
        return typeMapper.updateByExampleSelective(record, example);
    }

    @Override
    public int updateByExample(Type record, TypeExample example) {
        return typeMapper.updateByExample(record, example);
    }

    @Override
    public int updateByPrimaryKeySelective(Type record) {
        return typeMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKey(Type record) {
        return typeMapper.updateByPrimaryKey(record);
    }

    @Override
    public Type transformCommandToEntity(TypeFormCommand command) {
        Type type = new Type();
        BeanUtils.copyProperties(command, type);
        return type;
    }

    @Override
    public TypeVO transformEntityToVO(Type entity) {
        TypeVO vo = new TypeVO();
        BeanUtils.copyProperties(entity, vo);
        return vo;
    }

    @Override
    public TypeVO transformCustomToVO(TypeCustom custom) {
        TypeVO vo = new TypeVO();
        BeanUtils.copyProperties(custom, vo);
        return vo;
    }

    @Override
    public List<TypeVO> transformEntitiesToTOs(List<Type> entities) {
        List<TypeVO> vos = new ArrayList<>();
        for (Type type : entities) {
            vos.add(transformEntityToVO(type));
        }
        return vos;
    }

    @Override
    public List<TypeVO> transformCustomsToTOs(List<TypeCustom> customs) {
        List<TypeVO> vos = new ArrayList<>();
        for (Type type : customs) {
            vos.add(transformEntityToVO(type));
        }
        return vos;
    }
}
